<template>
    <view>
        <view v-if="detail != null">
            <!--状态-->
            <view class="order_status">
                <image :src="cutprice_static_url+'mini/order-status.png'" mode="scaleToFill" class="imgll" />
                <view class="status_name">{{ detail.status_name }}</view>
            </view>

            <!--物流-->
            <view class="order_wuliu" v-if="(detail.express_number || null != null) && express_info != []" @click="see_wuliu" :data-value="params.id" style="display: none">
                <image :src="cutprice_static_url+'mini/daishouhuo.png'" mode="scaleToFill" class="imgll" />
                <view class="wuliu_name">{{ express_info.list[0].status }}</view>
                <view class="wuliu_time">{{ express_info.list[0].time }}</view>
            </view>

            <!-- 地址 -->
            <view v-if="detail.order_model == 0 || detail.order_model == 2" class="address bg-white spacing-mb">
                <image class="icon fl" :src="cutprice_static_url+'mini/dingwei.png'" mode="widthFix" />
                <view class="address-base oh">
                    <text v-if="(detail.address_data.alias || null) != null" class="address-alias">{{ detail.address_data.alias }}</text>
                    <text>{{ detail.address_data.name }}</text>
                    <text class="fr">{{ detail.address_data.tel }}</text>
                </view>
                <view class="address-detail oh">
                    <view class="text">
                        {{ detail.address_data.province_name }}{{ detail.address_data.city_name }}{{ detail.address_data.county_name }}{{ detail.address_data.address }}
                        <text
                            v-if="detail.order_model == 2 && (detail.address_data.lng || 0) > 0 && (detail.address_data.lat || 0) > 0"
                            class="cr-666 br address-map-submit"
                            @click="address_map_event"
                        >
                            {{$t('fengcheche.cutprice.order_detail_see_address_text')}}
                        </text>
                    </view>
                </view>
            </view>

            <!-- 商品列表 --> 
            <view class="goods bg-white spacing-mb">
                <view class="goods-item br-b-dashed oh" v-for="(item, index) in detail.items" :key="item">
                    <navigator :url="'/pages/fcc/cutprice/detail/detail?cut_id=' + item.goods_id" hover-class="none">
                        <image class="goods-image fl" :src="item.images" mode="aspectFill" />
                        <view class="goods-base">
                            <view class="goods-title multi-text">{{ item.title }}</view>
                            <block v-if="item.spec != null">
                                <view class="goods-attribute cr-888" v-for="(spec, index1) in item.spec" :key="spec">{{ spec.type }}:{{ spec.value }}</view>
                            </block>
                        </view>
                        <view class="oh goods-price">
                            <text class="sales-price">{{detail.currency_data.currency_symbol}}{{ item.price }}</text>
                            <text v-if="item.original_price > 0" class="original-price">{{detail.currency_data.currency_symbol}}{{ item.original_price }}</text>
                            <text class="buy-number">x{{ item.buy_number }}</text>
                        </view>
                    </navigator>
                </view>
                <view class="order-describe">{{ detail.describe }}</view>
            </view>

            <!-- 虚拟销售数据 -->
            <view v-if="detail.order_model == 3 && detail.pay_status == 1 && (detail.status == 3 || detail.status == 4)" class="panel-item spacing-mt site-fictitious">
                <view class="panel-title">{{ site_fictitious.title || $t('fengcheche.cutprice.order_detail_key_info_text') }}</view>
                <view class="panel-content bg-white oh">
                    <view v-if="(site_fictitious.tips || null) != null" class="tips-value">
                        <rich-text :nodes="site_fictitious.tips"></rich-text>
                    </view>
                    <view class="item br-b-dashed oh" v-for="(item, index) in detail.items" :key="item">
                        <image class="left-image br fl" :src="item.images" mode="aspectFill" />

                        <view class="right-value fr">
                            <rich-text v-if="(item.fictitious_goods_value || null) != null" :nodes="item.fictitious_goods_value"></rich-text>
                            <text v-else class="cr-888">{{$t('fengcheche.cutprice.order_detail_no_info_text')}}</text>
                        </view>
                    </view>
                </view>
            </view>

            <!-- 自提信息 -->
            <view
                v-if="detail.order_model == 2 && (detail.status == 2 || detail.status == 3) && (detail.extraction_data || null) != null"
                class="panel-item spacing-mt site-extraction"
            >
                <view class="panel-title">{{$t('fengcheche.cutprice.order_detail_pickup_info_text')}}</view>
                <view class="panel-content bg-white oh">
                    <view>
                        <text>{{$t('fengcheche.cutprice.order_detail_pickup_code_text')}}：</text>
                        <text class="code">{{ detail.extraction_data.code || $t('fengcheche.cutprice.order_detail_not_pickup_text') }}</text>
                    </view>
                    <image v-if="(detail.extraction_data.images || null) != null" class="br qrcode" :src="detail.extraction_data.images" mode="aspectFill" />
                </view>
            </view>

            <!-- 订单基础数据 -->
            <view v-if="detail_list.length > 0" class="panel-item spacing-mt">
                <view class="panel-title">{{$t('fengcheche.cutprice.order_detail_order_info_text')}}</view>
                <view class="panel-content bg-white">
                    <view class="item br-b oh" v-for="(item, index) in detail_list" :key="item">
                        <view class="title fl">{{ item.name }}</view>

                        <view class="content cr-888 fl br-l">{{ item.value }}</view>
                    </view>
                </view>
            </view>

            <!-- 扩展数据 -->
            <view v-if="extension_data.length > 0" class="panel-item spacing-mt extension-list">
                <view class="panel-title">{{$t('fengcheche.cutprice.order_detail_ext_data_text')}}</view>
                <view class="panel-content bg-white">
                    <view class="item br-b oh" v-for="(item, index) in extension_data" :key="item">
                        <text class="title">{{ item.name }}</text>

                        <text class="content cr-888 br-l">{{ item.tips }}</text>
                    </view>
                </view>
            </view>

            <view class="panel-item spacing-mt teamlist">
                <view class="panel-title">{{$t('fengcheche.cutprice.cart_detail_who_help_me_title')}}</view>
                <view class="panel-content bg-white">
                    <view class="tuan_li" v-for="(item, index) in detail.teamusers" :key="item">
                        <image :src="item.user.avatar" mode="aspectFill" />

                        <view class="whois">
                            <text class="t1">{{ item.user.user_name_view }}</text>
                            <text class="t2" :decode="true">{{ item.add_time }}</text>
                        </view>

                        <view class="liright">
                            <view class="tinfo">{{$t('fengcheche.cutprice.cart_detail_cut_howmuch_before')}}{{ currency_symbol }}{{ item.price }}{{$t('fengcheche.cutprice.cart_detail_cut_howmuch_after')}}</view>
                        </view>
                    </view>
                    <view v-if="detail.teamusers.length == 0" class="tuan_li tc none_jilu">{{$t('fengcheche.cutprice.cutprice_no_record')}}</view>
                </view>
            </view>

            <!-- 结尾 -->
            <component-bottom-line :propStatus="data_bottom_line_status" :propMsg="$t('fengcheche.cutprice.data_bottom_line_msg')"></component-bottom-line>
        </view>

        <view v-if="detail == null">
            <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
        </view>
    </view>
</template>

<script>
const app = getApp();
import componentQuickNav from "@/components/quick-nav/quick-nav";
import componentPopup from '@/pages/fcc/cutprice/popup/popup';
import componentBadge from '@/components/badge/badge';
import componentNoData from "@/components/no-data/no-data";
import componentBottomLine from "@/components/bottom-line/bottom-line";
import componentOnlineService from "@/components/online-service/online-service";
import { cutprice_base_info } from '@/pages/fcc/cutprice/public/common.js';
var cutprice_static_url = app.globalData.get_static_url('cutprice', true);
var common_static_url = app.globalData.get_static_url('common');
export default {
	components: {
		componentQuickNav,
	    componentPopup,
	    componentBadge,
		componentNoData,
		componentBottomLine,
		componentOnlineService
	},
    data() {
        return {
            currency_symbol: app.globalData.currency_symbol(),
            params: null,
			cutprice_static_url: cutprice_static_url,
			common_static_url: common_static_url,
            data_list_loding_status: 1,
            data_list_loding_msg: '',
            data_bottom_line_status: false,
            detail: null,
            detail_list: [],
            extension_data: [],
            site_fictitious: null,
            express_info: [],
            status: '',
            time: '',
            alias: '',
            name: '',
            tel: '',
            lng: '',
            lat: '',

            code: '',
            images: '',
            length: 0,
			// 多语言
			lang_info:{},
        };
    },
    onLoad(params) {
        //params['id'] = 4;
        this.setData({
            params: params
        });
		this.init();
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.init();
    },
    methods: {
		// 加载之前
		init() {
			// 先获取语言基础信息
			cutprice_base_info()
			.then(data=>{
				this.init_before(data)
				.then(()=>{
					this.init_real();
				});
			});
		},
		// 设置本页参数
		init_before(data){
			var self = this;
			return new Promise((resolve, reject) => {
				self.setData({
					lang_info: data.cutprice_lang_info,
					currency_symbol: app.globalData.get_config('currency_symbol'),
				});
				uni.setNavigationBarTitle({
				    title: self.$t('fengcheche.cutprice.order_detail_page_title')
				});
				resolve();
			});
		},
        init_real() {
            var self = this;
            uni.showLoading({
                title: this.$t('fengcheche.cutprice.loading_tips')
            });
            this.setData({
                data_list_loding_status: 1
            });
            uni.request({
                url: app.globalData.get_request_url('OrderDetail', 'order', 'cutprice'),
                method: 'POST',
                data: {
                    id: this.params.id
                },
                dataType: 'json',
                success: (res) => {
                    console.log(res);
                    uni.hideLoading();
                    uni.stopPullDownRefresh();

                    if (res.data.code == 0) {
                        var data = res.data.data;
						/*var temp_detail_data_list = [];
						if(temp_detail_data_list.length > 0){
							for (var i in temp_detail_data_list) {
								if(temp_detail_data_list[i]['value'] == 'payment_name'){
									temp_detail_data_list[i]['value'] = (data.data.payment_name || '') + ((data.data.is_under_line_text || null) == null ? '' : '（' + data.data.is_under_line_text + '）');
								}else{
									temp_detail_data_list[i]['value'] = ((data.data[temp_detail_data_list[i]['value']] || null) != null) ? data.data[temp_detail_data_list[i]['value']] : '';
								}
							}
						}*/
                        self.setData({
                            detail: data.data,
                            detail_list: [
								//{ name: this.$t('user-order-detail.user-order-detail.346376'), value: data.data.warehouse_name || '' },
								//{ name: this.$t('user-order-detail.user-order-detail.io6p5k'), value: data.data.order_model_name || '' },
								{ name: this.$t('user-order-detail.user-order-detail.n18sd2'), value: data.data.order_no || '' },
								{ name: this.$t('user-order-detail.user-order-detail.yxwu8n'), value: data.data.status_name || '' },
								{ name: this.$t('user-order-detail.user-order-detail.23qj7m'), value: data.data.pay_status_name || '' },
								{ name: this.$t('user-order-detail.user-order-detail.vg4jb1'), value: data.data.price || '' },
								{ name: this.$t('user-order-detail.user-order-detail.2y7l13'), value: data.data.total_price || '' },
								//{ name: this.$t('user-order-detail.user-order-detail.6ub2j0'), value: data.data.preferential_price || '' },
								//{ name: this.$t('user-order-detail.user-order-detail.8b18q8'), value: data.data.increase_price || '' },
								{ name: this.$t('user-order-detail.user-order-detail.516tlr'), value: data.data.pay_price || '' },
								{ name: this.$t('user-order-detail.user-order-detail.0e1sfs'), value: (data.data.payment_name || '') + ((data.data.is_under_line_text || null) == null || (data.data.payment_name || null) == null ? '' : '（' + data.data.is_under_line_text + '）') },
								{ name: this.$t('user-order-detail.user-order-detail.2b5fc8'), value: data.data.user_note || '' },
								{ name: this.$t('user-order-detail.user-order-detail.h2c78h'), value: data.data.add_time || '' },
								//{ name: this.$t('user-order-detail.user-order-detail.9vivhl'), value: data.data.confirm_time || '' },
								{ name: this.$t('user-order-detail.user-order-detail.wn83rn'), value: data.data.pay_time || '' },
								{ name: this.$t('user-order-detail.user-order-detail.1674dc'), value: data.data.delivery_time || '' },
								{ name: this.$t('user-order-detail.user-order-detail.0i938r'), value: data.data.collect_time || '' },
								{ name: this.$t('user-order-detail.user-order-detail.1jpv4n'), value: data.data.cancel_time || '' },
								{ name: this.$t('user-order-detail.user-order-detail.8o2of3'), value: data.data.close_time || '' },
							],
                            extension_data: data.data.extension_data || [],
                            site_fictitious: data.site_fictitious || null,
                            data_list_loding_status: 3,
                            data_bottom_line_status: true,
                            data_list_loding_msg: ''
                        });
                    } else {
                        self.setData({
                            data_list_loding_status: 2,
                            data_bottom_line_status: false,
                            data_list_loding_msg: res.data.msg
                        });

                        if (app.globalData.is_login_check(res.data, self, 'init')) {
                            app.globalData.showToast(res.data.msg);
                        }
                    }
                },
                fail: () => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    self.setData({
                        data_list_loding_status: 2,
                        data_bottom_line_status: false,
                        data_list_loding_msg: this.$t('fengcheche.cutprice.request_data_error_tips')
                    });
                    app.globalData.showToast(this.$t('fengcheche.cutprice.request_data_error_tips'));
                }
            });
        },

        getwuliu() {
            var self = this;
            uni.request({
                url: app.globalData.get_request_url('index', 'index', 'aliexpress'),
                method: 'POST',
                data: {
                    order_id: this.params.id,
                    express_id: this.detail.express_id,
                    express_number: this.detail.express_number,
                    type: 1,
                    tablename: 'PluginsCutpriceOrderAddress'
                },
                dataType: 'json',
                success: (res) => {
                    uni.stopPullDownRefresh();
                    console.log(res);

                    if (res.data.code == 0) {
                        var data = res.data.data;
                        self.setData({
                            express_info: data
                        });
                    } else {
                        app.globalData.showToast(res.data.msg);
                    }
                },
                fail: () => {
                    uni.stopPullDownRefresh();
                    app.globalData.showToast(this.$t('fengcheche.cutprice.request_data_error_tips'));
                }
            });
        },

        // 查看物流
        see_wuliu(e) {
            uni.navigateTo({
                url:
                    '/pages/fcc/cutprice/orderexpress/orderexpress?order_id=' +
                    this.params.id +
                    '&express_id=' +
                    this.detail.express_id +
                    '&express_number=' +
                    this.detail.express_number
            });
        },

        // 地图查看
        address_map_event(e) {
            if ((this.detail.address_data || null) == null) {
                app.globalData.showToast(this.$t('fengcheche.cutprice.order_detail_address_wrong_tips'));
                return false;
            }

            var ads = this.detail.address_data;
            var lng = parseFloat(ads.lng || 0);
            var lat = parseFloat(ads.lat || 0);

            if (lng <= 0 || lat <= 0) {
                app.globalData.showToast(this.$t('fengcheche.cutprice.order_detail_lnglat_wrong_tips'));
                return false;
            }

            uni.openLocation({
                latitude: lat,
                longitude: lng,
                scale: 18,
                name: ads.alias || '',
                address: (ads.province_name || '') + (ads.city_name || '') + (ads.county_name || '') + (ads.address || '')
            });
        }
    }
};
</script>
<style>
@import './orderdetail.css';
</style>
